#include "BlockQueue.hpp"
#include "Task.cc"
#include <time.h>
#include <cstdlib>
#include <unistd.h>
using namespace ns_blockqqueue;

void* consumer(void* args)
{
    BlockQueue<int>* bq = (BlockQueue<int>*)args;
    while(true)
    {
        //sleep(1);
        int data = 0;
        bq->Pop(&data);
        cout << "消费者消费了一个数据：" << data << endl;
    }    
}
void* produter(void* args)
{
    BlockQueue<int>* bq = (BlockQueue<int>*)args;
    while(true)
    {
        sleep(5);
        //1.制造数据
        int data = rand() % 20 + 1;
        cout << "生产者生产数据：" << data << endl;
        bq->Push(data);  
    }
}

int main()
{
    srand((long long)time(nullptr));
    BlockQueue<int>* bq = new BlockQueue<int>();
    pthread_t c, p;

    pthread_create(&c, nullptr, consumer,(void*)bq);
    pthread_create(&p, nullptr, produter,(void*)bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);

    return 0;
}
